From the type class counter of the last chapter some more specialized counters can be derived. Letīs assume we need the following counters:

  • an address_counter, with the modified method count_up which increments value by 4 instead of 1 and
  • an up_down_counter, with an additional method count_down which decrements value.

For Implementation of these new counters, you donīt have to repeat the declarations which are already made in the class counter. The existing attributes and methods will be inherited and just new or modified functionalities or properties have to be specified.

The keywords new ... with are used to derive classes. The following example shows the derivation of the counter classes:


type address_counter is
  new class
counter with

  for signal, variable
    -- method to redefine
    procedure count_up;
  end for;

end class address_counter;

type up_down_counter is
  new class
counter with

  for signal, variable
    -- new method
    procedure count_down;
  end for;

end class up_down_counter;

address_counter and up_down_counter are derived from counter. They inherit all attributes and methods from parent class counter. address_counter redefines the count_up method, up_down_counter defines a new method count_down.